using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

using modEscenario;
using modElenco;
using modUtileria;
using modGuionistas;

namespace AirSpaceDef
{

    public class Game1 : Microsoft.Xna.Framework.Game
    {
        public void SetFrameRate ( int frames )
        {
            double dt = (double)1000 / (double)frames;
            graphics.SynchronizeWithVerticalRetrace = false;
            this.TargetElapsedTime = TimeSpan.FromMilliseconds ( dt );
            graphics.ApplyChanges ( );
        }


        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        public Game1 ( )
        {
            graphics = new GraphicsDeviceManager ( this );
            Content.RootDirectory = "Content";
            graphics.PreferredBackBufferHeight = 600;
            graphics.PreferredBackBufferWidth =1000;

            this.Window.AllowUserResizing = true;

            this.IsMouseVisible = true;

            SCutileria.folder = Content;

            modDatos._BlackGlobal.graphics = graphics;
        }

        protected override void Initialize ( )
        {
            SCGuionistas.definirEscena(SCDirector.primerEscena());
            SetFrameRate (60);
            base.Initialize ( );
        }

        protected override void LoadContent ( )
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch ( GraphicsDevice );
        }

        protected override void UnloadContent ( )
        {
            
        }

        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update ( GameTime gameTime )
        {
            // Allows the game to exit
            if (GamePad.GetState ( PlayerIndex.One ).Buttons.Back == ButtonState.Pressed)
                this.Exit ( );

            SCGuionistas.definirEscena(modElenco.SCDirector.seguirLibreto());
            SCescenario.ensayar ( gameTime );
            
            base.Update ( gameTime );
        }

        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw ( GameTime gameTime )
        {
            GraphicsDevice.Clear ( Color.White );

            SCescenario.actuar ( ref spriteBatch );

            base.Draw ( gameTime );
        }
    }
}
